﻿using Masuit.Tools.Html;
using Masuit.Tools.Hardware;
using System.Text.RegularExpressions;
using Masuit.Tools.Systems;
using Masuit.Tools.Strings;
using Masuit.Tools.Files;
using SharpCompress.Common;
using System.Collections.Generic;
using System.IO;
using Masuit.Tools.Database;
using Masuit.Tools.Excel;
using System.ComponentModel;

namespace Masuit.Tools
{
    class Program
    {
        private class CustomException : Exception
        {
            public CustomException(string msg) : base(msg)
            {

            }
        }
        static void Main(string[] args)
        {
            //获取电脑的CPU型号
            //var cpu = SystemInfo.GetCpuInfo();
            //var hardInfo = SystemInfo.GetDiskInfo()[0].SerialNumber;
            //Console.WriteLine("硬盘信息："+hardInfo);

            //if (cpu.Count>0)
            //{
            //    foreach (var item in cpu)
            //    {
            //        Console.WriteLine("CPU型号："+item.Type);
            //    }

            //}
            //Console.ReadKey();



            //匹配大陆身份证号
            //var match = "1234".MatchIdentifyCard();
            //Console.WriteLine(match);


            //string localUsedIp = SystemInfo.GetLocalUsedIP().ToString();// 获取本机当前正在使用的IP地址
            //Console.WriteLine(localUsedIp);



            //var num1 = 2342349.45.ToChineseMoney(); // 壹佰贰拾叁元肆角伍分
            //var num2 = 123.45.ToChineseNumber(); // 一百二十三点四五

            //Console.WriteLine(num1);
            //Console.WriteLine(num2);



            //如果是并行调用呢，会重复吗？挺好，没重复
            //Parallel.For(1, 50, (item,state) =>
            //{
            //    var id = GetSnowFlake();
            //    Console.WriteLine(id);
            //});

            //var xml = File.ReadAllText("test.xml");
            //var tmp = new Template(xml);
            //tmp.Set("PatName", "万金油");
            //string s = tmp.Render();// throw 模版变量{{greet}}未被使用
            //Console.WriteLine(s);

            //Zip();

            //var a = new MyClass()
            //{
            //    A = "aa"
            //};
            //var b = new MyClass()
            //{
            //    B = true
            //};
            //var c = new MyClass()
            //{
            //    C = 3
            //};
            //var merge = a.Merge(b, c); // 合并后对象：A = "aa"，B = true，C = 3
            //Console.WriteLine(merge.B);



            //var name = "女";
            //var mask = name.Mask();
            //Console.WriteLine(mask);


            var list = new List<Person>() { 
                new Person(){ Name="张三",Age =13,Gender="男",Avatar=File.OpenRead("Avatar/1.jpg")},
                new Person(){ Name="李四",Age =13,Gender="女",Avatar=File.OpenRead("Avatar/2.jpg")}
            };
            var stream = list.ToDataTable().ToExcel(""); //自定义列名导出
            using (var fs = File.Create("D:/temp/a.xlsx"))
            {
                stream.CopyTo(fs);
            }
            Console.WriteLine("操作完成");
            Console.ReadKey();
        }

        public class Person
        {
            [Description("姓名")]
            public string Name { get; set; }
            [Description("年龄")]
            public int Age { get; set; }
            [Description("性别")]
            public string Gender { get; set; }
            [Description("头像")]
            public Stream Avatar { get; set; }

        }

        public class MyClass
        {
            public string A { get; set; }

            public bool? B { get; set; }

            public int? C { get; set; }
        }
        public static void Zip()
        {
            string zip = "D:/test.zip";
            string dir = "D:/temp";
            HttpClient client = new HttpClient();
            var se = new SevenZipCompressor(client);
            se.Zip(dir, zip, "", ArchiveType.Zip);//压缩成zip
        }

        public static string GetSnowFlake()
        {
            // 静态调用
            return SnowFlakeNew.NewId;// 改良版雪花id，对时间回拨不敏感
        }
    }
}
